package com.itheima.health.h5.controller;

import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Setmeal;
import com.itheima.health.service.SetmealService;
import com.itheima.health.vo.SetmealVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SetmealController {

    @Reference(timeout = 1500,mock = "com.itheima.health.h5.controller.SetmealServiceMock")
    private SetmealService setmealService;

    @GetMapping("setmeal/findAllSetmeal")
    public Result findAll(){
        List<Setmeal> list = setmealService.list();
        if (list == null){
            Result result = new Result();
            result.setFlag(false);
            return result;
        }
        return new Result(list);
    }


    @GetMapping("setmeal/findSetMealDetailById/{id}")
    public Result findSetMealDetailById(@PathVariable("id") int id){
        SetmealVO setMealDetailById = setmealService.findSetMealDetailById(id);
        if (setMealDetailById == null){
            throw new RuntimeException("访问人数过多，请稍后访问");
        }
        return new Result(setMealDetailById);
    }
}
